package Persistencia;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Vector;

import Negocio.LoteSimple;
import Negocio.Mineral;

public class AdmPersistenciaMineral extends AdministradorPersistencia{
	
private static AdmPersistenciaMineral instancia;
	
	
	
	public static AdmPersistenciaMineral getInstancia() {
		if (instancia == null)
			instancia = new AdmPersistenciaMineral();
		return instancia;
	}
	
	
	public Vector<Mineral> selectAll()
	{
		try
		{
			
			Vector <Mineral>rta = new Vector<Mineral>();
			Connection c = PoolConnection.getPoolConnection().getConnection();
			Statement s = c.createStatement();
			ResultSet result = s.executeQuery("Select * from mineral");
			while (result.next())
			{
				int codigo = result.getInt(1);
				String nom = result.getString(2);
				Mineral min = new Mineral(codigo, nom);
				rta.add(min);
				
			}
			PoolConnection.getPoolConnection().realeaseConnection(c);
			return rta;
		}
		catch(Exception e)
		{
			
		}
		return null;
	}


	@Override
	public void delete(Object d) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void insert(Object o) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public Vector<Object> select(Object o) {
		Vector<Object> respuesta = null;
		try{
			Mineral a = (Mineral)o;
			Connection con = PoolConnection.getPoolConnection().getConnection();
			PreparedStatement s = con.prepareStatement("select * from Mineral where codigo = ?");
			s.setLong (1,a.getCodigo());
			ResultSet rta = s.executeQuery();
			if(rta.next()){	
				a.setNombre(rta.getNString(2));
			}
			respuesta = new Vector <Object>();
			respuesta.add(a);
		}catch(Exception e){
			System.out.println(e.getStackTrace());
		}
		return respuesta;
	}


	@Override
	public void update(Object o) {
		// TODO Auto-generated method stub
		
	}
}
